package cn.edu.lsnu.mbti.util;

import cn.edu.lsnu.mbti.entity.Department;

import java.util.ArrayList;
import java.util.List;

public class DelRepeatUtils {

    /**
     * 自定义去重
     * @param list
     */
    public static List<Department> delRepeatList(List<Department> list) {
        // 新集合
        List<Department> newList = new ArrayList<>(list.size());
        list.forEach(i -> {
            if (!newList.contains(i)) { // 如果新集合中不存在则插入
                newList.add(i);
            }
        });
        return newList;
    }

    public static void main(String[] args) {
        List list = new ArrayList<Department>();
        Department d1 = new Department();
        d1.setId("653eb6305f1a47af9ab1438e4c68d231");
        d1.setName("工学");
        d1.setMajorName("[计算机科学与技术,物联网,软件工程,土木工程]");
        list.add(d1);

        Department d2 = new Department();
        d2.setId("7cdeaedf02c3402bb7861f82e448e5c5");
        d2.setName("理学");
        d2.setMajorName("[数学,物理学]");
        list.add(d2);

        list.add(d1);
        list.add(d1);
        list.add(d1);

        List list1 = delRepeatList(list);
        System.out.println(list);
        System.out.println("===================================================");
        System.out.println(list1);
    }

}
